<?php
$link = mysql_connect('localhost','cs4350','!@'); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysql_error()); 
}
else {
    echo 'You are connected to the cs4350 database server!</br>';
}
if (!mysql_select_db( 'todo', $link)) {
    die('Aw snap, no database named todo...');
}
else {
    echo 'You are now using the todo database!</br>';
}
die();

$Name;
$URL;

if ($_POST['attachName'] == NULL){
	$Name = $_POST['attachURL'];
	$URL = true;
} else{
	$Name = $_POST['attachName'];
	$URL = 0;
}

$sql = "INSERT INTO attach VALUES ('Auto_increment','$_POST[id]','$Name','$URL')";
die($sql);

$test = 'SELECT * FROM list';

$result = mysql_query($sql, $link);
$testResult = mysql_query($test, $link);

if (!$result) {
	die($sql);
//    die('Invalid query: ' . mysql_error());
}
else {
    // print_r($result);
    // var_dump($result);
    
	//echo 'Task added </br>';	//change to redirect or reload later
	header('location:view.php?user='.$_POST["username"]);
	
    mysql_free_result($result);
	mysql_free_result($testResult);
}
?>